package alvin.hwang.tinygrid;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

public class JsonDataGenerator {

	private static final int ROW_TOTAL = 20;
	private static final int CELL_TOTAL = 15;
	private static final String DEFAULT_INFO = "-TEST-";

	private static final int PAGE = 1;
	private static final int TOTAL = ROW_TOTAL;

	public static void writeXml() throws IOException {
		System.out.println("--------------------starting---------------------");
		File file = new File("WebRoot/tinygrid/data-json.js");
		Writer out = new FileWriter(file);
		StringBuffer buffer = new StringBuffer();
		buffer.append("var data = {");
		buffer.append("");
		buffer.append("page:").append(PAGE).append(",");
		buffer.append("total:").append(TOTAL).append(",");
		buffer.append("rows:[");
		for (int row = 0; row < ROW_TOTAL; row++) {
			buffer.append("[");
			for (int cell = 0; cell < CELL_TOTAL; cell++) {
				buffer.append("\"").append(DEFAULT_INFO).append(row).append(cell).append("\"").append(
						(cell < CELL_TOTAL - 1) ? "," : "");
			}
			buffer.append("]").append((row < ROW_TOTAL - 1) ? "," : "");
		}
		buffer.append("]};");
		out.write(buffer.toString());
		out.flush();
		out.close();
		System.out.println("--------------------done---------------------");
	}

	public static void main(String[] args) throws IOException {
		JsonDataGenerator.writeXml();
	}
}
